﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Zerg
{
	public class ActionExtractorTrick : ActionProduceDrone
	{
		public static new ActionExtractorTrick Instance = new ActionExtractorTrick();
		private ActionExtractorTrick() : base() { }
		public override bool HaveTechnology(IBuildOrder bo) { return true; }
		public override void OnProductionStarted(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			state.Drone_Building++;
		}
		public override void OnProductionFinished(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			state.Drone++;
			state.Drone_Building--;
			state.WorkersOnMinerals++;
		}
		public override bool HaveResources(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			return
				state.Extractor.Total + 1 <= bo.State.Bases.Total * 2 &&
				AvailableProducer(bo) > 0 &&
				bo.State.Minerals >= Minerals + 25 &&
				bo.State.Supply == bo.State.Food;
		}
		public override bool IsInvalid(IBuildOrder bo)
		{
			ZergState state = bo.State as ZergState;
			if (bo.State.Supply != bo.State.Food) return true;
			if (state.Extractor.Total + 1 > bo.State.Bases.Total * 2) return true;
			if (bo.State.Minerals < Minerals + 25 && bo.State.WorkersOnMinerals == 0) return true;
			return false;
		}
		public override string EventName { get { return "ActionSpawnDrone"; } }
	}
}
